<?php
namespace Home\Controller;
use Think\Controller;

class GoodsController extends Controller{
    public function checkout(){
        $car = \Home\Tool\CarTool::getIns();
        $this->assign('car',$car->items());
        $this->display();
    }
    public function goods(){
        $goodsModel = D('Admin/goods');
        $goods_info = $goodsModel->find(I('get.goods_id'));

        $comments = $goodsModel->relationGet('comment');

        $this->assign('comments',$comments);

        if($goods_info){
            $this->hist($goods_info);
        }

        $catModel = D('Admin/Cat');
        $this->assign('mbx',$catModel->mbx($goods_info['cat_id']));

        $this->assign('goods_info',$goods_info);
        $this->display();
    }

    public function hist($goods_info){
        $hist = session('?hist')?session('hist'):array();
        $g['goods_name'] = $goods_info['goods_name'];
        $g['shop_price'] = $goods_info['shop_price'];

        $hist[$goods_info['goods_id']] = $g;
        if(count($hist) > 5){
            $k = key($hist);
            unset($hist[$k]);
        }

        session('hist',$hist);
        // session('hist',null);
        // var_dump(session('hist'));
    }


    public function pj(){
        // var_dump($_POST);exit;
        // $_POST['content'] = $_POST['editorValue'];
        $_POST['pubtime'] = time();
        D('Comment')->add($_POST);
    }

}
